package com.thon.controller.system;

import java.util.List;

import javax.jws.soap.SOAPBinding.Use;
import javax.validation.Valid;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.thon.commons.security.utils.ShiroUser;
import com.thon.controller.util.BaseController;
import com.thon.entity.system.User;
import com.thon.service.system.UserService;

/**
 * @author thon
 */
@Controller
public class WelcomeController extends BaseController{

	@Autowired
	private UserService userService;
	
	public User getUser(@RequestParam(value = "id", required = false) Integer id) {
		if (id != null) {
			return userService.getUser(id);
		}
		return null;
	}

	@RequestMapping(value={"/","/welcome"}, method = RequestMethod.GET)
	public String listUser(Model model) {
		List<User> users = userService.listAllUsers();
		
		model.addAttribute("users", users);
		return "welcome";
	}
	
	/**
	 * 更新Shiro中当前用户的用户名.
	 */
	private void updateCurrentUserName(String userName) {
		ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
		user.name = userName;
	}
}
